<?php

$mapping = array(
    '/pic/?$' => '/upload_ff.html',
    '/pic/upload/?$' => 'upload.php',
    '/pic/info/(.*)?$' => 'picinfo.php',
    '/pic/mark/(.*)?$' => 'mark.php',
);
function get_mapping(){
    global $mapping;
    $rst = array();
    foreach($mapping as $k => $v){
        $k = '/' . str_replace("/", "\\/", $k) . '/';
        $rst[$k] = $v;
    }
    //var_dump($rst);
    return $rst;
}

function run(){
    $mapping = get_mapping();
    $uri = getURI();
    foreach($mapping as $k => $v){
       if (preg_match($k, $uri)) {
           include $v;
           return;
       }
    }
    return ;
}
function getURI(){
    switch (TRUE) {
        case isset($_SERVER['HTTP_X_REWRITE_URL']):
            return $_SERVER['HTTP_X_REWRITE_URL'];
        case isset($_SERVER['REDIRECT_URL']):
            return $_SERVER['REDIRECT_URL'];
        case isset($_SERVER['REQUEST_URI']):
            return $_SERVER['REQUEST_URI'];             
        case isset($_SERVER['ORIG_PATH_INFO']):
            $uri = $_SERVER['ORIG_PATH_INFO'];      
            if(!empty($_SERVER['QUERY_STRING'])) {
                $uri .= '?' . $_SERVER['QUERY_STRING'];
            }
            return $uri;
        default:
            return '';
    }
}


//echo(getURI());

run();
